package com.apache.code;


import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class PDFtoimage {
    public static void main(String[] args) throws IOException {
        pdf();

    }
    // https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.html
    private static void pdf() throws IOException {
        PdfDocument pdf = new PdfDocument("test.pdf");
        BufferedImage image;
        for(int i = 0; i< pdf.getPages().getCount();i++){
            image = pdf.saveAsImage(i);
            File file = new File( String.format("ToImage-img-%d.png", i));
            ImageIO.write(image, "PNG", file);
        }
        pdf.close();
    }


    public void pdftoWORD(){
    PdfDocument pdf = new PdfDocument("test.pdf");
    pdf.saveToFile("ToWord.docx",FileFormat.DOCX);
}

